﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Vintner.Masters.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "VINT";
        }

        public override string Module()
        {
            return "MAST";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCounter((int)Counters.Customers, Properties.Resources.CN_Customers);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            //if (nameSpace.ApplicationPath == "Plumber.Plumber.Masters.Forms.Masters")
            //    frm.ScroungerList.Add()
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);

            #region VI_Customers

            if (SearchTable(VI_Customers.Name))
            {
                newTable.NewTable(VI_Customers.Name);

                newTable.AddColumn(VI_Customers.Customer);
                newTable.AddColumn(VI_Customers.Description);
                newTable.AddColumn(VI_Customers.Title);
                newTable.AddColumn(VI_Customers.Address);
                newTable.AddColumn(VI_Customers.ZipCode);
                newTable.AddColumn(VI_Customers.City);
                newTable.AddColumn(VI_Customers.County);
                newTable.AddColumn(VI_Customers.Phone1);
                newTable.AddColumn(VI_Customers.Phone2);
                newTable.AddColumn(VI_Customers.Fax);
                newTable.AddColumn(VI_Customers.Refer1);
                newTable.AddColumn(VI_Customers.Refer2);
                newTable.AddColumn(VI_Customers.Email);

                newTable.AddColumn(VI_Customers.DestGoods1);
                newTable.AddColumn(VI_Customers.DestGoods2);
                newTable.AddColumn(VI_Customers.TaxNo);
                newTable.AddColumn(VI_Customers.FiscalCode);

                newTable.AddColumn(VI_Customers.Disabled);
                newTable.AddColumn(VI_Customers.Blocked);

                newTable.AddPrimaryKey(VI_Customers.Customer);

                newTable.Create();
            }

            #endregion

            #region VI_Descriptions

            if (SearchTable(VI_Descriptions.Name))
            {
                newTable.NewTable(VI_Descriptions.Name);

                newTable.AddColumn(VI_Descriptions.Type);
                newTable.AddColumn(VI_Descriptions.Code);
                newTable.AddColumn(VI_Descriptions.Description);

                newTable.AddPrimaryKey(new iColumn[] { VI_Descriptions.Type, VI_Descriptions.Code });

                newTable.Create();
            }

            #endregion

            #region VI_TaxCode

            if (SearchTable(VI_TaxCode.Name))
            {
                newTable.NewTable(VI_TaxCode.Name);

                newTable.AddColumn(VI_TaxCode.Code);
                newTable.AddColumn(VI_TaxCode.Description);
                newTable.AddColumn(VI_TaxCode.Percent);

                newTable.AddPrimaryKey(VI_TaxCode.Code);

                newTable.Create();
            }

            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            return true;
        }
    }
}